<?php

class Obj_DBTable_LocationContentPage extends Zend_Db_Table_Abstract
{
    protected $_name = 'content_pages';
    protected $_primary = 'ID';
    
    
    public function getLocationContentPages($parent, $type, $activeOnly = false) {
    	$select = $this->select()->from($this, array('ID', 'Title', 'alias', 'Order'))->where('ParentID = ?', (int)$parent)->where('ParentType = ?', (int)$type);
    	if ($activeOnly === true) $select->where('active = 1');
    	return $this->fetchAll($select)->toArray();
    }
     
    public function getLocationContentPage($id) {
    	$select = $this->select()->from($this)->where('ID = ?', (int) $id);
    	$res = $this->fetchRow($select);
    	if ($res) {
    		return $res->toArray();
    	}
    	return false;
    }
    
    public function findLocationContentPage($parent, $type, $alias) {
    	$select = $this->select()->from($this)->where('ParentID = ?', (int) $parent);
    	$select->where('ParentType = ?', (int) $type);
    	$select->where('alias = ?', trim($alias));
    	$select->where('active = 1');
    	//echo $select->__toString();
    	$res = $this->fetchRow($select);
    	
    	if ($res) {
    		return $res->toArray();
    	}
    	return false;
    }
    
    public function delete($where)
    {
        return $this->_db->delete($this->_name, $where);
    }    
    public function getLinkRow($id, $type) {
    	$select = $this->select()->from($this, array('a2' => 'alias', 'a1' => new Zend_Db_Expr("'info'")));
    	if ($type == CONTENT_TYPE_COUNTRY) {
    		$select->join('countries', 'content_pages.ParentID = countries.ID', array('a0' => 'alias'));
    	}
    	if ($type == CONTENT_TYPE_REGION) {
    		$select->join('regions', 'content_pages.ParentID = regions.ID', array('a0' => 'alias'));
    	}
    	$select->where('content_pages.ID = ?', $id);
    	$select->setIntegrityCheck(false);
    	$res = $this->fetchRow($select);
    	if ($res) {
    		return $res->toArray();
    	}
    	return false;
    }
}